using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using  UnityEngine.UI;

public class BackpackDragItem : MonoBehaviour
{
    private RectTransform rectTransform;
    private Image img;
    public Sprite defaultImg;
    private BackpackItem curItem;

    private void Start()
    {
        this.rectTransform = this.transform.GetComponent<RectTransform>();
        this.img = this.transform.GetComponent<Image>();
    }

    public void SetPos(Vector3 pos)
    {
        this.rectTransform.position = pos;
    }

    /// <summary>
    /// 设置图片 重置时不需要传参
    /// </summary>
    /// <param name="img"></param>
    public void SetItem(BackpackItem item = null)
    {
        if (item)
        {
            this.img.sprite = item.GetSprite();
            this.img.SetNativeSize();
            this.curItem = item;
        }
        else
        {
            this.img.sprite = defaultImg;
        }
        this.curItem = item;
    }

    public Sprite GetImage()
    {
        return this.img.sprite;
    }


    public BackpackItem GetItem()
    {
        return this.curItem;
    }
}
